from django.contrib import admin
from cloud_store_app.models import File
# Register your models here.
admin.site.site_header = '网盘后台管理系统'
@admin.register(File)
class FileAdmin(admin.ModelAdmin):
    list_display = ('name', 'size', 'type', 'upload_time', 'upload_user', 'file_path')
    list_filter = ('upload_user', 'type')
    search_fields = ('name', 'upload_user', 'type')
    def save_model(self, request, obj, form, change):
        obj.upload_user = request.user.username
        obj.type = request.FILES['file_path'].content_type
        obj.size = f'{request.FILES['file_path'].size} bytes'
        obj.name = request.FILES['file_path'].name
        super().save_model(request, obj, form, change)